/* $Id:army.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __ARMY_H
#define __ARMY_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "members.h"
#include "material.h"
#include "members.h"
#include "material.h"

#define loopArmyMembers(r,v) loopMap((r)->listMembers(),v,class members)
#define loopArmyGoods(r,v) loopSingle((r)->listGoods(),v,class material,list)
#define loopArmyMembers_wanted(r,v) loopMap((r)->listMembers_wanted(),v,class members)
#define loopArmyGoods_wanted(r,v) loopSingle((r)->listGoods_wanted(),v,class material,list)

class army {
    string name;
    map<string,class members> members;
    map<string,class material> goods;
    map<string,class members> members_wanted;
    map<string,class material> goods_wanted;
    int location;
public:
    army();

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : members
    class members& getMembers(const string v);
    map<string,class members>& listMembers();
    void setMembers(class members &v);
    void delMembers(const string v);
    const bool isMembers(const string v) const;

    // Field : goods
    class material& getGoods(const string v);
    list<class material>& listGoods();
    void setGoods(class material &v);
    void delGoods(const string v);
    const bool isGoods(const string v) const;

    // Field : members_wanted
    class members& getMembers_wanted(const string v);
    map<string,class members>& listMembers_wanted();
    void setMembers_wanted(class members &v);
    void delMembers_wanted(const string v);
    const bool isMembers_wanted(const string v) const;

    // Field : goods_wanted
    class material& getGoods_wanted(const string v);
    list<class material>& listGoods_wanted();
    void setGoods_wanted(class material &v);
    void delGoods_wanted(const string v);
    const bool isGoods_wanted(const string v) const;

    // Field : location
    const int getLocation() const;
    void setLocation(const int v);
    const string showLocation() const;

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopArmys(v) loopMap(army_repo.listArmy(),v,class army)

class armyRepository {
    map<string,army> armys;
public:
    class army& getArmy(const string v);
    void setArmy(class army& v);
    map<string,class army>& listArmy();
    void delArmy(const string v);
    const bool isArmy(const string v) const;
    multimap<string, sigc::signal<void, class army& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern armyRepository army_repo;

#endif // __ARMY_H
